﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>EnvGet - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The EnvGet function retrieves an environment variable." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>EnvGet</h1>

<p>检索环境变量.</p>

<pre class="Syntax">Value := <span class="func">EnvGet</span>(EnvVarName)</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>EnvVarName</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>要检索的<a href="../Concepts.htm#environment-variables">环境变量</a>的名称. 例如: <code>Path := EnvGet("Path")</code>.</p>
  </dd>

</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
<p>函数返回指定的环境变量的值. 如果指定的环境变量为空或不存在, 则返回空字符串.</p>

<h2 id="Remarks">备注</h2>
<p>操作系统限制每个环境变量的文本最多为 32 KB.</p>
<p>此函数的存在是因为<a href="../Variables.htm">普通脚本变量</a>没有存储在环境变量中. 这是因为性能会变差, 也因为操作系统将环境变量限制为 32 KB.</p>
<h2 id="Related">相关</h2>
<p><a href="EnvSet.htm">EnvSet</a>, <a href="../Concepts.htm#environment-variables">环境变量</a>, <a href="Run.htm">Run</a>, <a href="Run.htm">RunWait</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a class="ex_number" href="#ExBasic"></a>  检索一个环境变量, 并将其值存储在 <var>LogonServer</var>.</p>
<pre>LogonServer := EnvGet("LogonServer")</pre>
</div>

<div class="ex" id="ExProgramFiles">
<p><a class="ex_number" href="#ExProgramFiles"></a> 检索并报告 "Program Files" 目录的路径. 有关替代方法, 请参阅 <a href="RegRead.htm#ExProgramFiles">RegRead 示例 #2</a>.</p>
<pre>ProgramFilesDir := EnvGet(<a href="../Variables.htm#Is64bitOS">A_Is64bitOS</a> ? "ProgramW6432" : "ProgramFiles")
MsgBox "Program files are in: " ProgramFilesDir</pre>
</div>

<div class="ex" id="ExLocalAppData">
<p><a class="ex_number" href="#ExLocalAppData"></a> 检索并报告当前用户的本地 AppData 目录.</p>
<pre>LocalAppData := EnvGet("LocalAppData")
MsgBox A_UserName "'s Local directory is located at: " LocalAppData</pre>
</div>

</body>
</html>